package org.uugu.counter.Support;

/**
 * String工具类
 * Created by Silence on 2014/3/29.
 */
public class StringUtils {

    public static final String EMPTY = "";

    /**
     * 判断是否空白
     * @param str
     * @return
     */
    public static boolean isBlank(String str) {

        int strLen;
        if (str == null || (strLen = str.length()) == 0) {
            return true;
        }
        for (int i = 0; i < strLen; i++) {
            if ((Character.isWhitespace(str.charAt(i)) == false)) {
                return false;
            }
        }
        return true;

    }

    /**
     * 判断不是空白
     * @param str
     * @return
     */
    public static boolean isNotBlank(String str) {
        return !StringUtils.isBlank(str);
    }

    /**
     * 清理空字符
     * @param str
     * @return
     */
    public static String clean(String str) {
        return str == null ? EMPTY : str.trim();
    }

    /**
     * 字符串转换为数字
     * @param str
     * @return
     */
    public static int Str2Int(String str){
        if(isBlank(str)){
            return 0;
        }
        int num = Integer.valueOf(clean(str));

        return num;
    }
}
